<!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui" xmlns:pt="http://xmlns.jcp.org/jsf/passthrough" xmlns:c="http://java.sun.com/jsp/jstl/core">

<ui:decorate id="msrpDecoration" template="template.xhtml">

  <ui:define name="title">#{title}</ui:define>

  <ui:define name="body">

    <h:panelGroup id="pnlConsulta" rendered="#{managedBean.state eq null || managedBean.state eq 'consultar'}">

      <p:panel style="margin-bottom:20px" styleClass="fonte">

        <f:facet name="header">
          <div class="tituloCrud">#{title}</div>

          <div style="float: right;">
            <h:panelGrid columns="3" cellspacing="5">
              <h:commandButton actionListener="#{managedBean.search}" styleClass="buttonClass" value="Pesquisar">
                <f:ajax render="frmDados:panelTemplate" execute="@form" />
              </h:commandButton>
              <h:commandButton actionListener="#{managedBean.preparePersist}" styleClass="buttonClass" value="Incluir">
                <f:ajax render="frmDados:panelTemplate" execute="@form" />
              </h:commandButton>
              <h:commandButton styleClass="buttonClass" value="Exportar">
                <f:ajax render="frmDados:panelTemplate" execute="@form" />
              </h:commandButton>
            </h:panelGrid>
          </div>
        </f:facet>

        <ui:insert name="parametroConsulta" />

        <div class="linha"></div>

        <p:outputPanel id="pnlResultado">

          <p:dataTable id="tblDadosTb" var="beanEnt" binding="#{managedBean.tblData}" lazy="true" value="#{managedBean.resultSearch}" paginator="true" rows="20"
            rowKey="#{beanEnt.id}" selectionMode="single" paginatorPosition="bottom" rendered="false" emptyMessage="Não foram encontrados registros para consulta."
            scrollable="true" scrollHeight="490" resizableColumns="true" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">

            <ui:insert name="tabelaDados" />

            <p:column>
              <h:commandButton actionListener="#{managedBean.prepareMerge}" styleClass="btnEditar">
                <f:ajax render="frmDados:panelTemplate" />
              </h:commandButton>

              <h:commandButton actionListener="#{managedBean.prepareRemove}" styleClass="btnExcluir">
                <f:ajax render="frmDados:panelTemplate" />
              </h:commandButton>

              <ui:insert name="botaoExtraTabela" />

            </p:column>
          </p:dataTable>

        </p:outputPanel>

      </p:panel>

    </h:panelGroup>

    <h:panelGroup id="pnlEdicao" rendered="#{managedBean.state eq 'incluir' || managedBean.state eq 'alterar'}">

      <p:panel style="margin-bottom:20px" styleClass="fonte">

        <f:facet name="header">
          <div class="tituloCrud">#{title}-cadastro</div>

          <div style="float: right;">
            <h:panelGrid columns="4" cellpadding="15">
              <ui:insert name="botaoTopCadastro" />
            </h:panelGrid>
          </div>
        </f:facet>

        <ui:insert name="formCadastro" />

        <f:facet name="footer">
          <div style="float: right; display: block;">
            <h:panelGrid columns="4" cellpadding="15">
              <h:commandButton id="btnSalvar" value="Salvar" styleClass="buttonClass" rendered="#{managedBean.state eq 'incluir'}" actionListener="#{managedBean.persist}">
                <f:ajax render="frmDados:panelTemplate" execute="@form" />
              </h:commandButton>
              <h:commandButton id="btnAlterar" value="Salvar" styleClass="buttonClass" rendered="#{managedBean.state eq 'alterar'}" actionListener="#{managedBean.merge}">
                <f:ajax render="frmDados:panelTemplate" execute="@form" />
              </h:commandButton>
              <h:commandButton id="btnCancelar" value="Cancelar" styleClass="buttonClass" immediate="true" actionListener="#{managedBean.cancel}">
                <f:ajax render="frmDados:panelTemplate" execute="@form" />
              </h:commandButton>
            </h:panelGrid>
          </div>
        </f:facet>

      </p:panel>

    </h:panelGroup>

    <h:panelGroup rendered="#{managedBean.state eq 'excluir'}">

      <div style="height: 30px;">

        <div style="float: right;">
          <h:panelGrid columns="4" cellpadding="15">
            <ui:insert name="botaoTopExclusao" />
          </h:panelGrid>
        </div>

      </div>

      <div style="margin-left: -10px; border-bottom: solid 1px #000; margin-right: -10px; margin-bottom: 10px;"></div>

      <div style="width: 100%;">

        <ui:insert name="formExclusao" />

      </div>

      <div class="linha"></div>

      <div style="float: right;">
        <h:panelGrid columns="4" cellpadding="15">
          <h:commandButton id="btnSim" value="Sim" styleClass="buttonClass" actionListener="#{managedBean.remove}">
            <f:ajax render="frmDados:panelTemplate" execute="@form" />
          </h:commandButton>
          <h:commandButton id="btnNao" value="Cancelar" styleClass="buttonClass" immediate="true" actionListener="#{managedBean.cancel}">
            <f:ajax render="frmDados:panelTemplate" execute="@form" />
          </h:commandButton>
        </h:panelGrid>
      </div>

    </h:panelGroup>

    <h:panelGroup rendered="#{managedBean.state eq 'visualizar'}">

      <div style="height: 30px;">

        <div style="float: right;">
          <h:panelGrid columns="4" cellpadding="15">

          </h:panelGrid>
        </div>

      </div>

      <div style="margin-left: -10px; border-bottom: solid 1px #000; margin-right: -10px; margin-bottom: 10px;"></div>

      <div style="width: 100%;">

        <ui:insert name="formDetalhar" />

      </div>

      <div class="linha"></div>

      <div style="float: right;">
        <h:panelGrid columns="4" cellpadding="15">
          <h:commandButton id="btnCancelarView" value="Cancelar" styleClass="buttonClass" immediate="true" actionListener="#{managedBean.cancel}">
            <f:ajax render="frmDados:panelTemplate" execute="@form" />
          </h:commandButton>
        </h:panelGrid>
      </div>

    </h:panelGroup>



  </ui:define>

</ui:decorate>

</html>
